package edu.ynu.se.xiecheng.achitectureclass.nongye.controller;

import edu.ynu.se.xiecheng.achitectureclass.nongye.dao.WaterDAO;
import edu.ynu.se.xiecheng.achitectureclass.nongye.entity.Water;
import edu.ynu.se.xiecheng.achitectureclass.nongye.service.WaterService;
import edu.ynu.se.xiecheng.achitectureclass.common.controller.LogicController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "水质管理")
@RestController
@RequestMapping("/water")
public class WaterController extends LogicController<WaterService, WaterDAO, Water, Integer> {

    @Autowired
    public WaterController(WaterService waterService) {
        super(waterService);
    }

    @ApiOperation("根据ID获取水质信息")
    @GetMapping("/getwater")
    public Water getWaterById(@RequestParam Integer id) {
        return getService().GET(id);
    }

    @ApiOperation("获取所有水质信息")
    @GetMapping("/getAllwater")
    public List<Water> getAllWater() {
        return getService().getAll();
    }

    @ApiOperation("创建水质记录")
    @PostMapping("/postwater")
    public Water createWater(@RequestBody Water water) {
        return getService().POST(water);
    }

    @ApiOperation("更新水质记录")
    @PostMapping("/putwater")
    public Water updateWater(@RequestBody Water water) {
        return getService().PUT(water);
    }

    @ApiOperation("删除水质记录")
    @PostMapping("/deletewater")
    public void deleteWater(@RequestBody Water water) {
        getService().DELETE(water);
    }

    @ApiOperation("通过ID删除水质记录")
    @GetMapping("/deleteByIdwater")
    public void deleteWaterById(@RequestParam Integer id) {
        getService().DELETE(id);
    }
}
